import static java.lang.System.exit;

public class MyQueue {
    //采用的是先进先出
    //用链表
    //链表的头每次后移
    static class Node{
        public int val;
        public Node next;
        public Node(int val) {
            this.val = val;
        }
    }
    public Node last;
    public Node first;
    //尾插
    public void add(int data) {
        Node cur=new Node(data);
        //如果链表为空
        if(first==null) {
            last=cur;
            first=cur;
        } else {
            last.next=cur;
            last=cur;
        }
    }
    //头删
    public int Pop() {
        if(first==null) {
            System.out.println("队列为空");
            exit(0);
        }
        int sum=first.val;
        //当我的链表只有一个结点也要删除时，要考到尾结点会不会成为野指针
        if(first.next==null) {
            last=null;
        }
        first=first.next;
        return sum;
    }
    public void display() {
        while (!empty()) {
            System.out.println(Pop()+" ");
        }
    }
    public boolean empty() {
        return first==null;
    }
    public int Top() {
        if(empty()) {
            System.out.println("队列为空");
            exit(0);
        }
        return first.val;
    }
}
